package edu.tyut.game.logic.dao

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import edu.tyut.game.logic.model.Poem
import edu.tyut.game.logic.model.Poet
import edu.tyut.game.logic.model.User

@Database(entities = [User::class, Poet::class, Poem::class], version = 1)
abstract class GameDataBase : RoomDatabase() {

    abstract fun userDao(): UserDao

    companion object {

        private var instance: GameDataBase? = null

        @Synchronized
        fun getDatabase(context: Context): GameDataBase {
            instance?.let {
                return it
            }
            return Room.databaseBuilder(
                context.applicationContext,
                GameDataBase::class.java,
                "db_game"
            )
                .build()
                .apply {
                    instance = this
                }
        }
    }
}